import "babel-polyfill";

export default class Queue {
    head = {next: null}
    _length = 0;

    constructor() {
        this.tail = this.head;
        this.push(...arguments);
    }

    get [Symbol.toStringTag]() {
        return "Queue";
    }

    get length() {
        return this._length;
    }

    push() {
        for (let x of arguments) {
            this.tail = this.tail.next = {data: x, next: null};
            ++this._length;
        }
        return this._length;
    }
    pop() {
        if (this._length) {
            let data = this.head.next.data;
            this.head.next = this.head.next.next;
            if (--this._length === 0) {
                this.tail = this.head;
            }
            return data;
        }
    }
    top() {
        if (this._length) {
            return this.head.next.data;
        }
    }
};
